package com.example.androidcomplete0102.ch16;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.androidcomplete0102.R;

public class ShowDialogEx extends Activity {
	final static int SAMPLE_DLG=0;
	final static int QUESTION_DLG=1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_dialogex);
	}
	
	public void mOnClick(View v){
		Log.d("ShowDialogEx","onCreateDialog");
		switch(v.getId()){
		case R.id.call:
			showDialog(SAMPLE_DLG);
			break;
		case R.id.call2:
			showDialog(QUESTION_DLG);
			break;
		}
	}
	
	@Override
	protected Dialog onCreateDialog(int id) {
		Log.d("ShowDialogEx","onCreateDialog");
		switch(id){
		case SAMPLE_DLG:
			return new AlertDialog.Builder(this).setTitle("알림").setMessage("대화상자를 열었습니다").setIcon(R.drawable.ic_launcher).setPositiveButton("닫기", null).create();
		case QUESTION_DLG:
			return new AlertDialog.Builder(this).setTitle("질문").setMessage("밥먹었어요?").setPositiveButton("먹었다", null).setNegativeButton("굶었다", null).create();
		}
		return null;
	}
	
	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		Log.d("ShowDialogEx","onPrepareDialog");
		switch(id){
		case SAMPLE_DLG:
			break;
		case QUESTION_DLG:
			Calendar cal = Calendar.getInstance();
			String stime = String.format("%d : %d : %d", cal.get(Calendar.HOUR_OF_DAY),
					cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND));
			dialog.setTitle(stime);
			break;
		}
	}
}
